/**
 * 联系人名片。
 */
import QtQuick 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1

import com.yihu.xchat.enum 1.0
import com.yihu.xchat.model 1.0

Rectangle {
    id: contactVCard

    property string background: "qrc:/images/vcard_background.png"
    property string photo: ConfigSingleton.defaultAvatar
    property string bareJid: "-"
    property string nickName: "-"
    property string url: "-"
    property string email: "-"
    property string telephone: "-"
    property string mobile: "-"
    property string address: "-"
    property string description: "-"

    // 背景及头
    Rectangle{
        id: header

        anchors.top: parent.top
        anchors.right: parent.right
        anchors.left: parent.left

        height: 270
        color: "pink"

        // 背景
        Image {
            id: backgroundImg
            source: background

            anchors.top: parent.top
            anchors.left: parent.left

            height: parent.height
            width: implicitWidth * parent.height / implicitHeight   // 按比例计算背景宽度，并固定
        }

        Column {
            anchors.horizontalCenter: parent.horizontalCenter
            y: 40

            spacing: 20

            Rectangle{
                width: 102
                height: 102
                radius: width / 2
                color: "lightgray"

                anchors.horizontalCenter: parent.horizontalCenter

                RoundImage {
                    id: userPhoto
                    source: photo

                    border.width: 2
                    border.color: "lightgray"

                    anchors.fill: parent
                }
            }

            Text {
                anchors.horizontalCenter: parent.horizontalCenter

                text: bareJid
                color: "white"
                font.pointSize: 20
            }

            // 名片页面的快捷操作按钮，发送消息，视频等
            Row {
                anchors.horizontalCenter: parent.horizontalCenter
                spacing: 20

                Image {
                    source: "qrc:/images/group_more.png"

                    width: 32
                    height: 32

                    MouseArea {
                        z: 10
                        anchors.fill: parent

                        onClicked: {
                            if(bareJid == "-"){
                                messageDialog.title = "会话";
                                messageDialog.text = "请先选择一个联系人以开始会话";
                                messageDialog.icon = MessageDialog.Information;
                                messageDialog.visible = true;
                            } else {
                                // 打开会话
                                SessionsSingleton.createSession(bareJid, X.P2P);
                                rootView.switchTopLevelView(rootView.topLevelViews.sessionsView);
                            }
                        }
                    }
                }

                Image {
                    source: "qrc:/images/forward.png"

                    width: 32
                    height: 32

                    MouseArea {
                        z: 10
                        anchors.fill: parent

                        onClicked: {
                            console.info("Open forward dialog");
                        }
                    }
                }
            }
        }
    }

    // 详细信息
    Rectangle {
        id: body

        anchors.top: header.bottom
        anchors.right: header.right
        anchors.bottom: header.bottom
        anchors.left: header.left

        anchors.topMargin: 40

        Grid {
            anchors.horizontalCenter: parent.horizontalCenter

            columns: 2
            columnSpacing: 15
            rowSpacing: 10

            Text {
                text: "JID"
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: bareJid
            }

            Text {
                text: qsTr("昵称")
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: nickName
            }

            Text {
                text: "电子邮件"
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: email
            }

            Text {
                text: "主页"
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: url
            }

            Text {
                text: "固定电话"
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: telephone
            }

            Text {
                text: qsTr("手机")
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: mobile
            }

            Text {
                text: qsTr("地址")
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: address
            }

            Text {
                text: qsTr("说明")
                width: 40
                horizontalAlignment: Text.AlignRight
            }

            Text {
                Layout.minimumWidth: 40
                text: description
            }
        }
    }

    // 消息对话框
    MessageDialog {
        id: messageDialog
    }
}
